package show.me.the.money.dictionary;

import java.util.HashMap;
import java.util.Set;

import show.me.the.money.config.Sortable;


public class DictionaryItem implements Sortable{
	private String key;
	private String text;
	HashMap<String,String> props;
	private int index;
	public DictionaryItem(String key,String text){
		this.key  = key;
		this.text = text;
		props = new HashMap<String,String>();
	}
	
	public int getIndex(){
		return index;
	}
	
	public void setIndex(int i){
		index = i;
	}
	
	public String getKey(){
		return key;
	}
	
	public String getText(){
		return text;
	}

	public String getProperty(String propName){
		return getProperty(propName,"");
	}
	
	public String getProperty(String propName,String defaultValue){
		if(props.containsKey(propName)){
			return props.get(propName);
		}
		return defaultValue;
	}
	
	public void setProperty(String propName,String propValue){
		props.put(propName, propValue);
	}
	
	public HashMap<String,Object> data(){
		HashMap<String,Object> h = new HashMap<String,Object>();
		h.put("key", key);
		h.put("text",text);
		Set<String> nms = props.keySet();
		for(String nm:nms){
			Object value = props.get(nm);
			h.put(nm, value);
		}
		return h;
	}
	
	public String toString(){
		return key + "=" + text;
	}
}
